/**
 *  File name:     Screen.java
 *  Package name:  infiniteloop.samples.display
 *  Project name:  InfiniteLoop
 *  Author:        Miloš Mihajlović
 *  Year:          2011
 *  Description:   
 */

package infiniteloop.samples.display;

import java.awt.DisplayMode;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Window;

import javax.swing.JFrame;

public class Screen {
	private GraphicsDevice vc;
	
	public Screen() {
		GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
		vc = env.getDefaultScreenDevice();
	}
	
	public void setFullScreen(DisplayMode dm, JFrame window) {
		window.setUndecorated(true);
		window.setResizable(false);
		vc.setFullScreenWindow(window);
		
		if (dm != null && vc.isDisplayChangeSupported()) {
			try {
				vc.setDisplayMode(dm);
			} catch (IllegalArgumentException e) {
				// TODO: handle exception
				e.printStackTrace();
			}
		}
	}
	
	public Window getFullScreenWindow() {
		return vc.getFullScreenWindow();		
	}
	
	public void restoreScreen() {
		Window w = getFullScreenWindow();
		if (w != null) {
			w.dispose();
		}
		vc.setFullScreenWindow(null);
	}
}
